package cn.com.dcsgo.config;

import cn.com.dcsgo.constants.CoreConstant;
import cn.com.dcsgo.interceptor.LoginInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * WebMvcConfig
 *
 * @author Dcsgo
 * @since 21/5/2025 下午 3:38
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加登录拦截器 拦截所有请求但排除验证码、登录请求路径、文档相关接口
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        CoreConstant.CAPTCHA_URL,
                        CoreConstant.LOGIN_URL,
                        "/doc.html",
                        "/swagger-ui/**",
                        "/webjars/**",
                        "/v3/api-docs/**"
                );
        // 这里注意一定不要漏了开头的斜杠！
    }
}
